import { UserInfo_Login } from "@/http/UserInfo/apis";
import type { IUserInfo } from "@/models/IUserInfo";
import router from "@/router";
import { Authorization } from "@/stores/Authorization";
import { ElMessage } from "element-plus";

/**
 * 登录
 */
export const Login = async (dto: IUserInfo) => {
  let result = await UserInfo_Login(dto);
  if (result.code != "0") {
    ElMessage.error("登录失败，错误信息：" + result.message);
    return;
  }
  var authorization = Authorization();
  authorization.SetToken(result.result);
  
  //跳转到首页
  // router.push("/");
  router.push("/screendisplay")
};

/**
 * 登出
 */
export const Logout = () => {
  var authorization = Authorization();
  authorization.ResetToken();

  //跳转到首页
  router.push("/login");
};
